package edu.gatech.cs2340.group7.wheresmystuffapp.model;

import java.util.Calendar;
import java.util.Date;
/**
 * Date object used for items and accounts
 * @author tbowling3
 *
 */
@SuppressWarnings("serial")
public class CustomDate extends Date {

	private String dateEntered;
	private int month;
	private int day;
	private int year;

	/**
	 * Gets the date as a string in format MM-DD-YYYY
	 * @param dateEntered String in format MM-DD-YYYY
	 */
	public CustomDate(String dateEntered) {
		this.dateEntered = dateEntered;
		createDate();
	}

	/**
	 * Sets up the month, day, and year attributes of this object.  
	 * Breaks the string and parses the month, day, and year
	 */
	public void createDate() {
		if (dateEntered.length() == 10) {
			String m = dateEntered.substring(0, 2);
			month = Integer.parseInt(m);
			//System.out.println(month);
			String d = dateEntered.substring(3, 5);
			day = Integer.parseInt(d);
		//	System.out.println(day);
			String y = dateEntered.substring(6, 10);
			year = Integer.parseInt(y);
			//System.out.println(year);
		}else { //if the length is not 10 then just put the current date and the year
			month = Calendar.MONTH;
			day = Calendar.DAY_OF_MONTH;
			year = Calendar.YEAR;
		}
	}

	/**
	 * 
	 * @return Returns the date as a string
	 */
	public String getDateEntered() {
		return dateEntered;
	}

	/**
	 * @return The month of this date object
	 */
	public int getMonth() {
		return month;
	}

	/**
	 * @return The day of this date object
	 */
	public int getDay() {
		return day;
	}

	/**
	 * @return The year of this date object
	 */
	public int getYear() {
		return year;
	}
	
	/**
	 * Tests to see if this date object is after the given date object
	 * @param d Date object to be compared
	 * @return True if this date object is after the given date object, false otherwise
	 */
	public boolean after(CustomDate d){
		boolean result = false;
		if(this.year > d.getYear()){
			result = true;
		}
		if(this.year == d.getYear()){
			if(this.month > d.getMonth()){
				result = true;
			}
			if(this.month == d.getMonth()){
				if(this.day > d.getDay()){
					result = true;
				}
			}
		}
		return result;
	}
}
